<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Log in</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="__JS__/plugins/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="__CSS__/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="__CSS__/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="__CSS__/dist/css/AdminLTE.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="__JS__/plugins/iCheck/square/blue.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="__JS__/html5shiv.min.js"></script>
    <script src="__JS__/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition login-page">
<div class="login-box">
    <div class="login-logo">
        <a href=""><b>Admin</b>LTE</a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">登录后台</p>

        <form action="{:U('public/login')}" method="post">
            <div class="form-group has-feedback">
                <input type="text" class="form-control" placeholder="user" id="username" name="username" value="admin">
                <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" class="form-control" placeholder="Password" id="password" name="password" value="admin" onkeydown='if(event.keyCode==13){checkLogin();}'>
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="row">
                <div class="col-xs-8">
                </div>
                <!-- /.col -->
                <div class="col-xs-4">
                    <a href="javascript:void(0);" class="btn btn-primary btn-block btn-flat" onclick="checkLogin()">登录</a>
                </div>
                <!-- /.col -->
            </div>
        </form>

    </div>
    <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 2.2.3 -->
<script src="__JS__/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="__JS__/plugins/bootstrap/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="__JS__/plugins/iCheck/icheck.min.js"></script>
<script>
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
    });
</script>
<script>
    function checkLogin(){
        var username = $('#username').val();
        var password = $('#password').val();
        var formurl = $('#subForm').attr('action');

        if( username == '' || password ==''){
            $("#error_msg").text('用户名或密码不能为空');
            layer.alert('用户名或密码不能为空', {icon: 2});
            return;
        }

        $.ajax({
            url: formurl,
            type:'post',
            dataType:'json',
            data:{username:username,password:password},
            success:function(res){
                if(res.status==1){

                    top.location.href = '{:U("index/index")}';
                }else{
                    layer.alert(res.msg, {icon: 2});

                }
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('网络失败，请刷新页面后重试', {icon: 2});

            }
        })
    }
</script>
</body>
</html>
